package cn.com.session;

import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;

@WebServlet(name = "session01", value = "/session01")
public class session01 extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取Session对象
        HttpSession session = request.getSession();

        // 存储数据到Session中，使用setAttribute方法
        // 第一个参数是键（String类型），第二个参数是值（Object类型）
        session.setAttribute("username", "张三");
        session.setAttribute("userid", 1001);
        session.setAttribute("isLogin", true);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
